#ifndef _CONFIG_SERVER_H_H
#define _CONFIG_SERVER_H_H

#include <string>
#include <json/json.h>

#include <log4cxx/logger.h>

#include "ServerFrameWork.h"
#include "MysqlConnPool.h"

using std::string;

using namespace log4cxx;

class CnfSvr {
	public:
		int init(const char * listen_ip, unsigned short listen_port, int thread_num, const char * log_conf_file, \
			int socket_idle_timeout, int socket_send_tiemout, int socket_recv_timeout, int max_request_size, \
			const char * mysql_svr_host, unsigned short mysql_svr_port, \
			const char * mysql_user, const char * mysql_password, const char * mysql_db_name, \
			unsigned int mysql_pool_size);
		int start();
	protected:
		static int handle_socket_input_func(int fd, void * arg);
		int handle_get_all_conf(int fd);
		static int thread_init_func(void * arg);
		int dispatch_request(int cmd_id, json_object * j, string & response);
		int handle_get_all_cnf(json_object * j, string & response);
		int parse_request(const char * request, const int len, json_object * & j, int & cmd_id);
	private:
		string _listen_ip;
		unsigned short _listen_port;
		int _thread_num;
		string _log_conf_file;
		static LoggerPtr _logger;
		ServerFrameWork _sfw;
		string _log_cnf_file;
		int _socket_idle_timeout;
		MysqlConnPool _mysql_conn_pool;
		string _mysql_svr_host;
		unsigned short _mysql_svr_port;
		string _mysql_user;
		string _mysql_password;
		string _mysql_db_name;
		int _mysql_pool_size;
		int _socket_recv_timeout;
		int _socket_send_timeout;
		int _max_request_size;
};

#endif 
